package cc.surui.cpp 
{
	import flash.external.ExternalInterface;
	import flash.system.fscommand;
	/**
	 * ...
	 * @author Surui
	 */
	public class CPPFSCommand 
	{
		private static var _self:CPPFSCommand;
		private static var object:Object = new Object();
		public function CPPFSCommand() 
		{
			
		}
		public static function get self():CPPFSCommand {
			if ( !_self ) {
				_self = new CPPFSCommand();
			}
			return _self;
		}
		public function initCppCMD():void {
			ExternalInterface.addCallback("MsgBox", cppCallback);
		}
		
		/**
		 * 调用C++处理
		 * @param	cmd
		 * @param	params
		 * @param	handler
		 */
		public function call( cmd:String, params:String, handler:Function ):void {
			fscommand( cmd, params );
			object[Object(params).cmd] = handler;
		}
		
		public function cppCallback( msg ):void {
			(object["MsgBox"] as Function).call( object["MsgBox"], msg );
		}
	}

}